package com.mujin.keji.collectionsystem.module.message.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.listeners.CustomItemClickListener;
import com.mujin.keji.collectionsystem.module.message.dto.MsgDetail;

import java.util.List;


/**
 * 消息列表适配器
 *
 * @author weishixiong
 * @Time 2018-03-22
 */

public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.ViewHolder> {
    private Activity mContext;
    private List<MsgDetail> datas;
    private CustomItemClickListener listener;
    private String types[] = new String[]{"", "签到通知", "数据上传", "任务超时回收", "任务分配", "任务回收"};
    private int imageTypes[] = new int[]{R.drawable.image_message, R.drawable.image_msg_sign, R.drawable.image_msg_upload, R.drawable.image_msg_assimilator, R.drawable.image_msg_task,R.drawable.image_msg_assimilator};

    public MessageAdapter(Activity context, List<MsgDetail> datas, CustomItemClickListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_message_list, parent, false);
        ViewHolder viewHolder = new ViewHolder(view, listener);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.tvDate.setText(datas.get(position).getNoticeDate());
        holder.tvContent.setText(datas.get(position).getContent());
        //  String type	;//通知类型(1-签到通知 2-数据上传 3-任务回收 4-任务分配)	number	@mock=$order(1,2,3,4)
        holder.tvTitle.setText(types[datas.get(position).getType()]);
        holder.ivHead.setImageResource(imageTypes[datas.get(position).getType()]);
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvTitle;
        private TextView tvDate;
        private TextView tvContent;
        private ImageView ivHead;

        public ViewHolder(final View itemView, final CustomItemClickListener listener) {
            super(itemView);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
            tvDate = (TextView) itemView.findViewById(R.id.tv_date);
            tvContent = (TextView) itemView.findViewById(R.id.tv_content);
            ivHead = (ImageView) itemView.findViewById(R.id.iv_head);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.onItemClick(itemView, getLayoutPosition());
                }
            });

        }

    }
}
